<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

if (!function_exists('save_konten_statis_routes')) {
    function save_konten_statis_routes() {
        $CI = & get_instance();
        $CI->load->database();

        $this->db->select('slug');
        $query = $this->db->get('konten_statis');

        if ($query->num_rows() > 0) {
            $result = $query->result_array();            
            $query->free_result();
        } else {
            $result = array();
        }

        if (!empty($result )) {
            $data[] = '<?php if ( ! defined(\'BASEPATH\')) exit(\'No direct script access allowed\');';

            foreach ($result as $route) {
                $data[] = '$route[\'' . $route['slug'] . '\'] = \'static_pages\';';
            }
            $output = implode("\n", $data);
            write_file(APPPATH . 'cache/konten_statis_routes.php', $output);
        }

    }
}

if (!function_exists('save_member_routes')) {
    function save_member_routes() {
        $CI = & get_instance();
        $CI->load->database();
        
        $CI->db->select('id, username');
        $query = $CI->db->get('rc_users');

        if ($query->num_rows() > 0) {
            $result = $query->result_array();            
            $query->free_result();
        } else {
            $result = array();
        }

        if (!empty($result )) {
            $data[] = '<?php if ( ! defined(\'BASEPATH\')) exit(\'No direct script access allowed\');';

            foreach ($result as $route) {
                $data[] = '$route[\'' . $route['id'] . '\'] = \'rapor\';';
                if(!empty($route['username'])){
                    $data[] = '$route[\'' . $route['username'] . '\'] = \'rapor\';';
                }                
            }
            $output = implode("\n", $data);
            write_file(APPPATH . 'cache/member_routes.php', $output);
        }

    }
}